import fs from 'fs'
import path from 'path'

export async function hasFilesInDirectory(dirPath: string): Promise<boolean> {
    const files = await fs.promises.readdir(dirPath, {withFileTypes: true})

    for (const file of files) {
        const filePath = path.join(dirPath, file.name)
        const stat = await fs.promises.stat(filePath)

        if (!file.isDirectory() && !stat.isSymbolicLink()) {
            // Found a file
            return true
        }

        if (file.isDirectory()) {
            // Recursively check subdirectories
            const hasFiles = await hasFilesInDirectory(filePath)
            if (hasFiles) {
                // Found files in a subdirectory
                return true
            }
        }
    }

    return false
}